package com.example.actionbardemo;

import com.example.actionbardemo.fragment.BaseFragment;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;

public class TabNavActivity extends FuncListActivity implements ActionBar.TabListener {
	 private ActionBar actionBar;
	 /**tab标题*/
	private String[] items;
	
	@Override
	public int getContentViewID() {
		return R.layout.activity_tabnav;
	}
	
	@Override
	public boolean isBackIconVisible() {
		return true;
	}
	
	@Override
	public void initData() {
		items = getResources().getStringArray(R.array.nav_list);
	}
	
	@Override
	public void initView() {
	        actionBar = getActionBar();  
	        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);// tab导航模式必须设为NAVIGATION_MODE_Tabs  
	        //添加tab选项.
	        for(int i=0;i<items.length;i++){
	        	ActionBar.Tab tab = actionBar.newTab();
	        	tab.setText(items[i]);
	        	tab.setTabListener(this);
	        	actionBar.addTab(tab);
//	        	actionBar.addTab(actionBar.newTab().setText(items[i]).setTabListener(this));   //可以一步到位.
	        }
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		int position = tab.getPosition();
		String content = items[position];  
        BaseFragment newFragment = new BaseFragment(content);
        getSupportFragmentManager().beginTransaction().replace(R.id.fl_content, newFragment).commit();
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		
	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		
	}
	
}
